import { ExecutionContext, createParamDecorator } from "@nestjs/common";
import { NacosConfigClientService } from "../nacosConfigClient.service";


const nacosConfigFactory = async (options: {
  dataId: string,
  group: string,
  options ?:any
}, ctx: ExecutionContext):Promise<any> => {
  const request = ctx.switchToHttp().getRequest();
  console.log("-----------------")
  console.log(request.app)
  console.log("-----------------")
  const nacosConfigClientService = request.app.get(NacosConfigClientService) as NacosConfigClientService;
  console.log(nacosConfigClientService)
  return await nacosConfigClientService.getConfig(options.dataId, options.group, options?.options);
}
export const NacosConfig = createParamDecorator(nacosConfigFactory);
/**
 * @description: 获取nacos配置
 * @param {string} dataId
 * @param {string} group
 * @param {any} options
 * @return {ParameterDecorator}
 */
function NacosPropertySource(dataId: string, group: string,options?:any) {
  return NacosConfig({
    dataId, 
    group,
    options
  });
}

export default NacosPropertySource